package com.ruoyi.web.controller.xiaomi;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.bye.xiaomi_mall.domain.*;
import com.bye.xiaomi_mall.service.ITdGoodsCategoryService;
import com.bye.xiaomi_mall.service.ITdGoodsService;
import com.bye.xiaomi_mall.service.ITdRotateImageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品Controller
 *
 * @author ruoyi
 * @date 2025-03-15
 */
@RestController
@RequestMapping("/xiaomi_mall/goods")
public class TdGoodsController extends BaseController {
    @Autowired
    private ITdGoodsService tdGoodsService;

    /**
     * 查询商品列表
     */
    @PreAuthorize("@ss.hasPermi('system:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(TdGoods tdGoods) {
        startPage();
        List<TdGoods> list = tdGoodsService.selectTdGoodsList(tdGoods);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:goods:list')")
    @GetMapping("/selectGoodsType")
    public Map<String,Object> selectGoodsType() {
        Map<String,Object> map=new HashMap<>();
        List<TdGoodsCategory> list = tdGoodsService.selectGoodsType();
        map.put("list",list);
        return map;
    }


    @PreAuthorize("@ss.hasPermi('system:goods:list')")
    @GetMapping("/selectGoodsSp")
    public Map<String,Object> selectGoodsSp() {
        Map<String,Object> map=new HashMap<>();
        List<TdGoodsSpecifications> list = tdGoodsService.selectGoodsSp();

        map.put("list",list);
        return map;
    }



    @PreAuthorize("@ss.hasPermi('system:goods:list')")
    @GetMapping("/selectGoods")
    public Map<String,Object> selectGoods() {
        Map<String,Object> map=new HashMap<>();
        List<TdGoods> list = tdGoodsService.selectGoods();
        map.put("list",list);
        return map;
    }



    /**
     * 导出商品列表
     */
    @PreAuthorize("@ss.hasPermi('system:goods:export')")
    @Log(title = "商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TdGoods tdGoods) {
        List<TdGoods> list = tdGoodsService.selectTdGoodsList(tdGoods);
        ExcelUtil<TdGoods> util = new ExcelUtil<TdGoods>(TdGoods.class);
        util.exportExcel(response, list, "商品数据");
    }

    /**
     * 获取商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tdGoodsService.selectTdGoodsById(id));
    }

    /**
     * 新增商品
     */
    @PreAuthorize("@ss.hasPermi('system:goods:add')")
    @Log(title = "商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TdGoods tdGoods) {
        return toAjax(tdGoodsService.insertTdGoods(tdGoods));
    }

    /**
     * 修改商品
     */
    @PreAuthorize("@ss.hasPermi('system:goods:edit')")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TdGoods tdGoods) {
        return toAjax(tdGoodsService.updateTdGoods(tdGoods));
    }

    /**
     * 删除商品
     */
    @PreAuthorize("@ss.hasPermi('system:goods:remove')")
    @Log(title = "商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tdGoodsService.deleteTdGoodsByIds(ids));
    }















}
